﻿function GetValueFromRadioButtonList(radio) {

    var RB1 = document.getElementById(radio);
    var radio = RB1.getElementsByTagName("input");
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked)
            return radio[i].value;
    }
}
function SetValueForRadioButtonList(radio, value) {

    var RB1 = document.getElementById(radio);
    var radio = RB1.getElementsByTagName("input");
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].value == value)
            radio[i].checked = true;
        else
            radio[i].checked = false;
    }
}


function checkbrowser() {

    var browsertype = navigator.userAgent.toLowerCase();
    if (browsertype.indexOf('msie') != -1) {
        browser = 'isIE';
        return browser;
    }
    else if (browsertype.indexOf('netscape') != -1) {
        browser = 'isNS';
        return browser;
    }
    else if (browsertype.indexOf('safari') != -1) {
        browser = 'isSF';
        return browser;
    }
    else if (browsertype.indexOf('gecko') != -1) {
        browser = 'isFF';
        return browser;
    }
}
function CancelTabKey(evt) {

    evt = (evt || window.event);
    key = (evt.keyCode || evt.charCode || evt.which || 0);
    if (key == 9) {
        if (checkbrowser() == 'isIE')
            evt.returnValue = false;
        else {
            evt.preventDefault();
            evt.stopPropagation();
        }
    }
}
function DisableParentForm(btn) {

    document.getElementById(btn).onkeydown = CancelTabKey;

}
function trimLeft(str) {
    if (str == null) { return null; }
    for (var i = 0; str.charAt(i) == " "; i++);
    return str.substring(i, str.length);
}
function trimRight(str) {
    if (str == null) { return null; }
    for (var i = str.length - 1; str.charAt(i) == " "; i--);
    return str.substring(0, i + 1);
}
function trim(str) { return trimLeft(trimRight(str)); }
function trimLeftAll(str) {
    if (str == null) { return str; }
    for (var i = 0; str.charAt(i) == " " || str.charAt(i) == "\n" || str.charAt(i) == "\t"; i++);
    return str.substring(i, str.length);
}
function trimRightAll(str) {
    if (str == null) { return str; }
    for (var i = str.length - 1; str.charAt(i) == " " || str.charAt(i) == "\n" || str.charAt(i) == "\t"; i--);
    return str.substring(0, i + 1);
}
function replaceAll(varb, replaceThis, replaceBy) {
    newvarbarray = varb.split(replaceThis);
    newvarb = newvarbarray.join(replaceBy);
    return newvarb;
}
function trimAll(str) {
    return trimLeftAll(trimRightAll(str));
}
// isNull(value)
//   Returns true if value is null
function isNull(val) { return (val == ""); }

// isBlank(value)
//   Returns true if value only contains spaces
function isBlank(val) {
    return isNull(trimAll(val));
}

// isInteger(value)
//   Returns true if value contains all digits
function isInteger(val) {
    if (isBlank(val)) { return false; }
    for (var i = 0; i < val.length; i++) {
        if (!isDigit(val.charAt(i))) { return false; }
    }
    return true;
}

// isNumeric(value)
//   Returns true if value contains a positive float value
function isNumeric(val) { return (parseFloat(val) == (val * 1) && parseFloat(val) >= 0); }

// isArray(obj)
// Returns true if the object is an array, else false
function isArray(obj) { return (typeof (obj.length) == "undefined") ? false : true; }

// isDigit(value)
//   Returns true if value is a 1-character digit
function isDigit(num) {
    if (num.length > 1) { return false; }
    var string = "1234567890";
    if (string.indexOf(num) != -1) { return true; }
    return false;
}

// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
function setNullIfBlank(obj) { if (isBlank(obj.value)) { obj.value = ""; } }
function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}
function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}
